Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

html-to-text

Package Overview
Dependencies
Maintainers
2
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

html-to-text

Advanced html to plain text converter

  • 8.2.1
  • version8
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2M
increased by0.34%
Maintainers
2
Weekly downloads
 
Created

What is html-to-text?

The html-to-text npm package is designed to convert HTML documents into plain text. It can handle various HTML elements, preserving the basic structure and formatting in a text-only format. This is particularly useful for extracting text from HTML emails, web pages, or any HTML content for use in text-based formats.

What are html-to-text's main functionalities?

Convert HTML to plain text

This feature allows you to convert a string of HTML into a plain text format, with options such as word wrapping.

const htmlToText = require('html-to-text');
const html = '<h1>Hello World</h1>';
const text = htmlToText.fromString(html, {
  wordwrap: 130
});
console.log(text); // Outputs: 'Hello World'

Handling of tables

This feature enables the conversion of HTML tables into a tabular text format, preserving the layout of the data.

const htmlToText = require('html-to-text');
const html = '<table><tr><td>Foo</td><td>Bar</td></tr></table>';
const text = htmlToText.fromString(html, {
  tables: true
});
console.log(text); // Outputs a text representation of the table

Handling of lists

This feature converts HTML lists into plain text, with customizable prefixes for list items.

const htmlToText = require('html-to-text');
const html = '<ul><li>Item 1</li><li>Item 2</li></ul>';
const text = htmlToText.fromString(html, {
  unorderedListItemPrefix: '- '
});
console.log(text); // Outputs: '- Item 1\n- Item 2'

Handling of hyperlinks

This feature allows for the conversion of hyperlinks into plain text, with options to hide or display the URL based on the link text.

const htmlToText = require('html-to-text');
const html = '<a href='https://example.com'>Example</a>';
const text = htmlToText.fromString(html, {
  hideLinkHrefIfSameAsText: true
});
console.log(text); // Outputs: 'Example'

Other packages similar to html-to-text

Keywords

FAQs

Package last updated on 30 Jul 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc